// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// H [author] rhyme_lph
// S [email]  rhymelph@gmail.com
// V [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/utils/form_utils.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/form/value_select_form.dart';
import 'package:finance_app/src/widgets/input/form_input_field.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/provider/setting/preference/number_format_info_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:flutter/services.dart';

@RouterMeta(paramName: "numberFormatInfoPage")
class NumberFormatInfoPage extends StatefulWidget {
  final String title;
  final String value;

  const NumberFormatInfoPage({Key key, this.title, this.value})
      : super(key: key);

  @override
  _NumberFormatInfoPageState createState() => _NumberFormatInfoPageState();
}

class _NumberFormatInfoPageState extends State<NumberFormatInfoPage>
    with PagePresenter<NumberFormatInfoPage, NumberFormatInfoProvider> {
  @override
  PreferredSizeWidget get appBar => getDefaultAppBar(
        title: FormUtils.keyToName(widget.title),
      );

  @override
  void initState() {
    provider.initValue(widget.value);
    super.initState();
  }

  @override
  Widget get buildWidget => ListView(
        children: [
          FromInputField(
            tip: S.current.prefix,
            controller: provider.prefixController,
            focusNode: provider.prefixFocusNode,
          ),
          FromInputField(
            tip: S.current.digits,
            controller: provider.digitsController,
            focusNode: provider.digitsFocusNode,
            inputFormatterList: [
              FilteringTextInputFormatter.digitsOnly,
            ],
          ),
          listBuilder<String>(
            selector: (_, __) => __.preview,
            builder: (BuildContext context, String value, Widget child) =>
                ValueSelectForm(
              title: S.current.preview,
              value: value,
            ),
          ),
        ],
      );
}
